package com.czxy.spday02.controller;

import com.czxy.spday02.domain.User;
import com.czxy.spday02.service.UserService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;


//    @RequestMapping("/findAll")
//    public String show01(Model model) {
//
//        List<User> list = userService.findAll();
//        model.addAttribute("list",list);
//
//        return "/list.jsp";
//    }



    @GetMapping
    public ResponseEntity findAll() {

        try {

            System.out.println("执行findAll方法");
            List<User> list = userService.findAll();

            int i = 1/0;

            return ResponseEntity.ok(list);
        } catch (Exception e) {

            e.printStackTrace();

            return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR);
        }


    }



//        System.out.println("执行findAll方法");
//
//        List<User> list = userService.findAll();
//
//        return ResponseEntity.ok(list);
//
//    }


}
